import axios from "./http";

// 获取今日新闻信息
const queryNewsLatest = () => {
    return axios.get('/api/news_latest');
};

// 获取往日新闻信息
const queryNewsBefore = time => {
    return axios.get('/api/news_before', {
        params: {
            time
        }
    });
};

// 获取新闻详细信息
const queryNewsInfo = id => {
    return axios.get('/api/news_info', {
        params: {
            id
        }
    });
};

// 获取新闻评论/点赞信息
const queryNewsComments = id => {
    return axios.get('/api/story_extra', {
        params: {
            id
        }
    });
};

// 登录和注册
const login = ruleForm => {
    // ruleForm:是包含phone/code的对象
    return axios.post('/api/login', ruleForm);
};

// 发送验证码
const phoneCode = phone => {
    return axios.post('/api/phone_code', {
        phone
    });
};

// 检测是否登录
const checkLogin = () => axios.get('/api/check_login');

// 获取登录者信息
const userInfo = () => axios.get('/api/user_info');

// 收藏新闻
const store = newsId => axios.post('/api/store', { newsId });

// 移除收藏
const storeRemove = id => axios.get('/api/store_remove', { params: { id } });

// 获取收藏列表
const storeList = () => axios.get('/api/store_list');

export default {
    queryNewsLatest,
    queryNewsBefore,
    queryNewsInfo,
    queryNewsComments,
    login,
    phoneCode,
    checkLogin,
    userInfo,
    store,
    storeRemove,
    storeList
};